﻿using Newtonsoft.Json;
using System;
using System.IO;

namespace P2PTransmit.ViewModal
{
	public class Setting
	{
		public string SavePath;

		public string ErrorPath;

		public string MachineName;

		public int MaxDownloadCount;

		public int GlobalSpeedLimit;

		public int SpeedLimitPerTask;

		public bool AutoReceiveFile;

		public Setting()
		{
			bool flag = File.Exists("Config.dat");
			if (flag)
			{
				try
				{
					string value = File.ReadAllText("Config.dat");
					Setting setting = JsonConvert.DeserializeObject<Setting>(value);
					this.SavePath = setting.SavePath;
					this.ErrorPath = setting.ErrorPath;
					this.MachineName = setting.MachineName;
					this.MaxDownloadCount = setting.MaxDownloadCount;
					this.GlobalSpeedLimit = setting.GlobalSpeedLimit;
					this.SpeedLimitPerTask = setting.SpeedLimitPerTask;
					this.AutoReceiveFile = setting.AutoReceiveFile;
				}
				catch
				{
				}
			}
			else
			{
				this.SavePath = Environment.CurrentDirectory;
				this.ErrorPath = Environment.CurrentDirectory;
			}
		}

		public void Save()
		{
			File.WriteAllText("Config.dat", JsonConvert.SerializeObject(this));
		}
	}
}
